import React from 'react'
import PropTypes from 'prop-types'
import { connect } from 'react-redux'
import { withRouter } from 'react-router-dom'
import { checkCouponData, checkCouponInfo, editCoupon, checkOrgList, checkCouponProductList } from '../../actions/couponManage/coupon'
import { checkBusinessLevelSelect, checkProductList } from '../../actions/couponManage/createCoupon'

import { couponList,couponTotal,couponInfo,orgList,couponProductList,editCouponStatus } from '../../reducers/CouponManage/coupon'
import { getBusinessLevelSelect, getProductList, getProductListTotal } from '../../reducers/CouponManage/createCoupon'
import Coupon from '../../views/CouponManage/Coupon/index'
import { bindActionCreators } from 'redux'

const CouponContainer = ({
        couponList, 
        couponListTotal, 
        couponInfo,
        orgList, 
        businessLevelSelect,
        productList,
        productListTotal,        
        couponProductList,
        checkCouponData, 
        checkCouponInfo, 
        editCoupon, 
        checkOrgList,
        checkBusinessLevelSelect,
        checkProductList,
        checkCouponProductList,
        editCouponStatus
        }) => {    
    return <Coupon 
        couponList={couponList}
        couponListTotal={couponListTotal}
        couponInfo={couponInfo}
        orgList={orgList}
        businessLevelSelect={businessLevelSelect}
        productList={productList}
        productListTotal={productListTotal}        
        couponProductList={couponProductList}        
        editCouponStatus={editCouponStatus}        
        onCheckOrgList={(data)=> checkOrgList(data)}
        onCheckClick={(data)=> checkCouponData(data)}
        onExpandClick={(data)=> checkCouponInfo(data)}
        onHandleEdit={(data)=> editCoupon(data)}
        onCheckProduct={(data)=> checkProductList(data)}
        onCheckBusinessLevelSelect={(data)=> checkBusinessLevelSelect(data)}  
        onCheckCouponProductList={(data)=> checkCouponProductList(data)}         
    />
}

CouponContainer.propTypes = {
    couponList: PropTypes.array,
    couponListTotal: PropTypes.number,
    couponInfo: PropTypes.object,
    orgList: PropTypes.array,
    businessLevelSelect: PropTypes.array,
    productList: PropTypes.array,
    productListTotal: PropTypes.number,        
    onCheckClick: PropTypes.func,
    onExpandClick: PropTypes.func,
    onHandleEdit: PropTypes.func,
    couponProductList: PropTypes.array,
    onCheckCouponProductList: PropTypes.func,
}

const mapStateToProps  = (state) =>({
    couponList:couponList(state.coupon),
    couponListTotal:couponTotal(state.coupon),
    couponInfo:couponInfo(state.coupon),
    orgList:orgList(state.coupon),    
    businessLevelSelect:getBusinessLevelSelect(state.createCoupon),
    productList:getProductList(state.createCoupon),
    productListTotal:getProductListTotal(state.createCoupon),
    couponProductList:couponProductList(state.coupon),    
    editCouponStatus:editCouponStatus(state.coupon),    
})
const mapDispatchToProps = (dispatch) => ({
    checkCouponData: bindActionCreators(checkCouponData,dispatch),
    checkCouponInfo: bindActionCreators(checkCouponInfo,dispatch),
    editCoupon: bindActionCreators(editCoupon,dispatch),
    checkOrgList: bindActionCreators(checkOrgList,dispatch),
    checkProductList: bindActionCreators(checkProductList,dispatch),
    checkBusinessLevelSelect: bindActionCreators(checkBusinessLevelSelect,dispatch),  
    checkCouponProductList: bindActionCreators(checkCouponProductList,dispatch),    
})

export default withRouter(connect(
    mapStateToProps,
    mapDispatchToProps
  )(CouponContainer))